<!DOCTYPE html>
<html>
<head>
<title>Flappy Fash</title>
<meta type="keyword" content="变态版,Flappy-fash" />
<meta name="description" content="变态版Flappy bird由jtu唐制作，仅供娱乐"/>
<meta http-equiv = "Content-Type" content="txt/html;charset=UTF-8"/>
<script src="/js/jquery.js"></script>
<style>
canvas{
background:#eee;
}
</style>
</head>
<body style="margin:0px;padding:0px;text-align:center;overflow:hidden;">
	<div style="position:absolute;left:45%;top:40%;font-size:30px;display:none;color:red" id="gv">Game Over!</div>
	<div style="position:absolute;left:20%;top:20%;" id="bar">Score</div>
	<div style="display:none;position:absolute;top:45%;left:48%;color:red;cursor:pointer" id="game-start">开始游戏</div>
	<canvas height=1000 width=320 id="canvas"></canvas>
</body>
<script>
var ry=0,x=100,r=32;
var g = 2;
var h = window.innerHeight;
var downt=0;
var rp = h/2;
var z1=320,z2;
var fenshu = 0;
var isendd = false;
var h1 = Math.ceil(Math.random()*10+1),h2 = Math.ceil(Math.random()*10+1);
var status;
var can = document.getElementById("canvas");
var	can2d = can.getContext("2d");
$(document).ready(function(){
	$("#game-start").fadeIn();
	$("#canvas").click(upRect);
	$("#game-start").click(bstart);
});
function reset(){
	rx=150,ry=0,g = 2,downt=0;
	rp = h/2;
	z1=320,z2;
	fenshu = 0;
	isendd = false;
	h1 = Math.ceil(Math.random()*10+1),h2 = Math.ceil(Math.random()*10+1);
	$("#gv").fadeOut(1);
	$("#game-start").fadeOut(1);
}
function bstart(){
	reset();
	status = setInterval("start()",1000/30);
}
function timeManage(){
	if(ry >= h-30 || isendd)
	{
		$("#gv").fadeIn();
		$("#game-start").fadeIn();
		clearInterval(status);
	}
}
function showZ(x,y){
	can2d.beginPath();
	can2d.fillStyle = "green";
	can2d.rect(x,0,100,h/y);
	can2d.fill();
	can2d.rect(x,h/4+h/y,100,h);
	can2d.fill();
	can2d.closePath;
}
function updataMap(){
	z1-=5
	z2 = z1 + 260;
	if(z1 <= -100)
	{	
		z1=z2;
		h1=h2;
		z2=320;
		h2 = Math.ceil(Math.random()*10+1);
		fenshu ++;
	}
}
function updata(){
	var tt = document.getElementById("bar");
	tt.innerHTML = "Score:<br>"+fenshu;
}
function upRect(){
	ry = ry - 40;
	if(ry <= 0)ry=0;
	rp = ry;
	downt = 0; 
	ty = rp + 0.5*g*downt*downt;
}
function start(){
	downRect();
	isend();
	updataMap();
	updata();
	fash();
	if(timeManage() == -1)return -1;
}
function isend(){
	if((x+34) > z1 && (ry+14) > (h/4+h/h1))
	{
		if(x-34 < z1+100)isendd = true;
	}
	else if((x+34) > z1 && (ry-32) < (h/h1))
	{
		if(x - 34 <z1+100)isendd = true;
	}
}
function downRect(){
	ry = rp + 0.5*g*downt*downt;
	ryt = rp + 0.5*g*(downt+1)*(downt+1);//预判物体下一个位置
	if(ryt > h)
	{
		ry = h-20;
	}
	downt++;
}
function fash(){
		can2d.clearRect(0,0,320,h);
		showZ(z1,h1);
		showZ(z2,h2);
		can2d.beginPath();
		can2d.fillStyle = "black";
		can2d.arc(x,ry,r,Math.PI*0.8,Math.PI*1.8,false);
		can2d.arc(x-6,ry-18,r,0,Math.PI,false);
		can2d.fill();
		can2d.closePath();
		can2d.beginPath();
		can2d.fillStyle = "white";
		can2d.arc(x+8,ry-20,r/8,0,Math.PI*2,false);
		can2d.fill();
		can2d.closePath();
		can2d.beginPath();
		can2d.strokeStyle = "white";
		can2d.arc(x+22,ry-18,r/8,0,Math.PI,false);
		can2d.stroke();
		can2d.closePath();
	}
</script>
</html>